{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Image Browser"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example shows how to browse through a set of images with a slider."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import interact"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will use the digits dataset from [scikit-learn](http://scikit-learn.org/stable/)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "digits = datasets.load_digits()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def browse_images(digits):\n",
    "    n = len(digits.images)\n",
    "    def view_image(i):\n",
    "        plt.imshow(digits.images[i], cmap=plt.cm.gray_r, interpolation='nearest')\n",
    "        plt.title('Training: %s' % digits.target[i])\n",
    "        plt.show()\n",
    "    interact(view_image, i=(0,n-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a3d01c363bae49fdbdc10b9c8d6b6218",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=898, description='i', max=1796), Output()), _dom_classes=('widget-intera…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "browse_images(digits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {
     "0c884f05d0cb40178320ac5b1f344029": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.0.0",
      "model_name": "LayoutModel",
      "state": {}
     },
     "1461fd745aef4251b1490e6793199b18": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.0.0",
      "model_name": "LayoutModel",
      "state": {}
     },
     "2bb226276ed046a78b1bfa1bf8697a7e": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.2.0",
      "model_name": "IntSliderModel",
      "state": {
       "description": "i",
       "layout": "IPY_MODEL_1461fd745aef4251b1490e6793199b18",
       "max": 1796,
       "style": "IPY_MODEL_977de331262947c1b65c80dcb44b2f4a",
       "value": 898
      }
     },
     "30147ec2f5af4428864c7ae4fa60c910": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.0.0",
      "model_name": "LayoutModel",
      "state": {}
     },
     "3b0cfbf6ceb44fbfa2fac0a465020824": {
      "model_module": "@jupyter-widgets/output",
      "model_module_version": "1.0.0",
      "model_name": "OutputModel",
      "state": {
       "layout": "IPY_MODEL_0c884f05d0cb40178320ac5b1f344029",
       "outputs": [
        {
         "data": {
          "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAEICAYAAAByNDmmAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAADXdJREFUeJzt3X+s3XV9x/Hny4JjyI9mAw1SxoUpOLcEShoS0kUYbgsoUpeZCBtmNUvcH8NgZmZ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DOqtq3p3Uzk8CvWPMQ8PuANyY5ZXpQ4xLgCzOuadmShMl7uW1VdeWs6+lLVX2kqtZU1QKT/6s7q+qyGZfVi6p6AngsyenTm94KrOiDop3WRR9SVe1NcjnwJWAV8KmqemjGZfVhPfAe4D+SbJne9kdVdfsMa9Li3g9cN51stgPvnXE9yzLzj8kkDWcedtElDcSASw0z4FLDDLjUMAMuNcyASw0z4FLD/h8gmb6UzbDP+AAAAABJRU5ErkJggg==\n",
          "text/plain": "<Figure size 432x288 with 1 Axes>"
         },
         "metadata": {},
         "output_type": "display_data"
        }
       ]
      }
     },
     "977de331262947c1b65c80dcb44b2f4a": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.2.0",
      "model_name": "SliderStyleModel",
      "state": {
       "description_width": ""
      }
     },
     "a3d01c363bae49fdbdc10b9c8d6b6218": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.2.0",
      "model_name": "VBoxModel",
      "state": {
       "_dom_classes": [
        "widget-interact"
       ],
       "children": [
        "IPY_MODEL_2bb226276ed046a78b1bfa1bf8697a7e",
        "IPY_MODEL_3b0cfbf6ceb44fbfa2fac0a465020824"
       ],
       "layout": "IPY_MODEL_30147ec2f5af4428864c7ae4fa60c910"
      }
     }
    },
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
